
local FruitWidth = 0
local FruitItem = class("FruitItem", function(x, y, index)
			index = index or math.round(math.random() * 1000) % 8 + 1
			local sprite = display.newSprite(string.format("#fruit%d_1.png", index))
			sprite.fruitIndex = index
			sprite.x = x
			sprite.y = y
			sprite.isActive = false
			return sprite
		end)

function FruitItem:ctor()

end

function FruitItem:setActive(active)
	self.isActive = active

	local name = string.format("#fruit%d_%d.png", self.fruitIndex, active and 2 or 1)
	local frame = display.newSpriteFrame(name)
	self:setSpriteFrame(frame)

	if active then
		self:stopAllActions()
		local scaleTo1 = cc.ScaleTo:create(0.1, 1.1)
		local scaleTo2 = cc.ScaleTo:create(0.05, 1.0)
		self:runAction(cc.Sequence:create(scaleTo1, scaleTo2))
	end
end

function FruitItem:getWidth()
	if FruitWidth == 0 then
		local sprite = display.newSprite("#fruit1_1.png")
		FruitWidth = sprite:getTextureRect().width
	end
	return FruitWidth
end

return FruitItem
